package com.example.personalcenter;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class InterestActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private Button btnOk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interest);

        radioGroup = findViewById(R.id.radioGroup);
        btnOk = findViewById(R.id.btnOk);

        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int checkedId = radioGroup.getCheckedRadioButtonId();
                if (checkedId == -1) {
                    Toast.makeText(InterestActivity.this, "请选择一项兴趣", Toast.LENGTH_SHORT).show();
                    return;
                }
                String interest = ((android.widget.RadioButton) findViewById(checkedId)).getText().toString();
                com.example.personalcenter.util.SharedPrefUtil.saveInterest(InterestActivity.this, interest);
                setResult(RESULT_OK);
                finish();
            }
        });
    }
}